package cn.yuemouren.tree.segment.leetcode;

import cn.yuemouren.tree.segment.SegmentMerge;
import cn.yuemouren.tree.segment.SegmentTree;

/**
 * @Author: Timi
 * @Description: TODO
 * @Date: 2020/7/9 21:18
 * @Version: v1.0
 */
public class ValidParenthesis_307 {
    private SegmentTree<Integer> segmentTree = null;

    public ValidParenthesis_307(int[] nums) {
        if(nums.length > 0){
            Integer[] data = new Integer[nums.length];
            for (int i = 0; i < data.length; i++)
                data[i] = nums[i];
            segmentTree = new SegmentTree<Integer>(data,(a,b) -> a + b);
        }
    }

    public void update(int i, int val) {
        if(segmentTree == null)
            throw new IllegalArgumentException("error");
        segmentTree.set(i,val);
    }

    public int sumRange(int i, int j) {
        if(segmentTree == null)
            throw new IllegalArgumentException("error");
        return segmentTree.query(i,j);
    }

    public static void main(String[] args) {
        int[] nums = {-1};
        ValidParenthesis_307 asf = new  ValidParenthesis_307(nums);
        System.out.println(asf.sumRange(0, 0));
        asf.update(0, 1);
        System.out.println( asf.sumRange(0, 0));
       ;
        System.out.println(true);
    }
}
